<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* three@0.121.1 (https://github.com/mrdoob/three.js)
* LegacyJSONLoader (https://github.com/omkarap55/three-Legacy-JSON-Loader)
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title data-i18n="resources.title_buildings"></title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            width: 100%;
        }

        #map {
            width: 100%;
            height: 100%;
        }

    </style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
<script type="text/javascript" include="three@0.121.1,LegacyJSONLoader" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script type="text/javascript" src="./js/ThreeApplication.js"></script>
<script>


    var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
       " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

    var host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-china/rest/maps/ChinaDark";

    var map, threeLayer;

    map = new mapboxgl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        },
        center: [104.07099170795755, 30.560115990796447],
        zoom: 19.54,
        pitch: 60,
        bearing: 36
    });

    map.on('load', function() {
      addThreeLayer();
    });

    function addThreeLayer() {

        //gl参数表示使用webgl渲染，forceRefresh强制不断刷新three的场景
        threeLayer = new mapboxgl.supermap.ThreeLayer('three');
        threeLayer.on("initialized", render);
        map.addLayer(threeLayer);
        function render() {
            var renderer = threeLayer.getThreeRenderer(),
                scene = threeLayer.getScene(),
                camera = threeLayer.getCamera();

            this.light = new THREE.PointLight(0xffffff, 0.8);
            this.light.position.copy(camera.position);
            scene.add(this.light);
            scene.add(new THREE.AmbientLight(0x04589e));
            var directionalLight = new THREE.DirectionalLight(0xffffff, 1);
            directionalLight.position.set(0, 0, 0);
            scene.add(directionalLight);
            ThreeApplication
                .register(renderer, scene, camera)
                .setTargetLayer(threeLayer)
                .setPosition([104.071092, 30.560304])
                .start();
        }

        //均匀光照，与相机位置同步
        threeLayer.on("render", function () {
            // threeLayer.light.position.copy(threeLayer.renderer.camera.position);
            threeLayer.light.position.set(0, 0, 0);
        });
    }

</script>

</body>
</html>
